<?php
include '../config/auth.php';

function success(){
    $result=[
        'error'=>'0',
        'message'=>'成功'
    ];
    return json_encode($result);
}

function error($msg){
    $data=[
        'error'=>'1',
        'message'=>$msg
    ];
    return json_encode($data);
}

$user_name=$_POST['username'];
$room_id=$_POST['room_id'];
$message=$_POST['message'];
if($message==null){
    die();
}
$config = include '../config/db.php';
$db = new PDO($config['dsn'],$config['username'],$config['password']);
$statement=$db->prepare('insert into message_record set user_name=:user_name,room_id=:room_id,`time`=:t,message=:message');
$result=$statement->execute([
    ':user_name'=>$user_name,
    ':room_id'=> $room_id,
    ':t'=>time(),
    ':message'=>$message
]);
echo success();